﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using Atom.Utility;

namespace MedicalReport
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string path = System.Windows.Forms.Application.StartupPath + "\\Medlicense.ini";
            if (!File.Exists(path))
            {
                MessageBox.Show("没有授权文件，请联系软件制造商！");
                return;
            }
            using (StreamReader sr = File.OpenText(path))
            {
                string input = string.Empty;
                if ((input = sr.ReadLine()) != null)
                {
                   
                    try
                    {
                        string d = EncryptDecrypt.Decrypt(input).Substring(0, 10);
                        DateTime de = Convert.ToDateTime(d);
                        DateTime now = (DateTime.Now > new DateTime(2011, 1, 1) ? DateTime.Now : new DateTime(2011, 1, 1));

                        if (EncryptDecrypt.Decrypt(input).Substring(10).Equals(EncryptDecrypt.GetCpuID()))
                        {
                            if (now < de)
                            {
                                Application.Run(new FrmMain());
                            }
                            else
                            {
                                MessageBox.Show("产品使用已过期，请联系注册！");

                                Application.Run(new FrmRegist());
                            }
                        }
                        else
                        {
                            Application.Run(new FrmRegist());
                        }
                    }
                    catch 
                    {

                        MessageBox.Show("不合法的授权文件，请联系软件制造商！");
                    }
                   
                }
                else
                {
                    Application.Run(new FrmRegist());
                }
            }

           
           // Application.Run(new FrmMain());
        }
    }
}
